iOS Recipes (for Mary Smithson) by Matt Drance & Paul Warren
Author:Matt Drance & Paul Warren
Language: eng
Format: epub
Tags: Pragmatic Bookshelf
ISBN: 1-934356-74-3
Publisher: The Pragmatic Bookshelf, LLC (271010)
[self repositionShadow:self.contentTopShadow];
self.contentTopShadow.hidden = NO;
} else {
self.topShadow.hidden = YES;
self.contentTopShadow.hidden = YES;
}
The next step, adjusting the bottom shadows, is a little trickier. Because table views receive -layoutSubviews so frequently, we only want to bother adjusting the shadows if they’re showing. How do we know if the bottom shadows are exposed? We need to find out where the bottom of the table content is. “That’s easy,” you might be thinking. “Just get the last cell in the last section and get its frame; if it’s nil, then the bottom clearly isn’t showing.” But what if the last section has no rows? What if we have twenty sections, and the last three sections are empty? We could iterate backwards until we find the row that is definitively last in the table, but doing this inside every call to -layoutSubviews is excessive.
OK, so using the "last cell" may not be reliable. What about the table’s contentSize? If the table runs off the screen, contentSize.y is a valid metric. But it turns out that contentSize is always at least the height of the table itself—even if the actual content is much smaller. So if we have a 460 pixel-high table with a single 44 pixel row, contentSize.y is reported as 460, not 44 as we might expect.
It turns out UIKit already performs this measurement for us when it positions the table footer. If we have a table footer, we can just query its frame to find out the table’s bottom Y coordinate.
What if we don’t have a table footer? Easy: we insert one by overriding the -tableFooterView getter as a lazy initializer. If a footer is already installed, we just use that by messaging the superclass. If a footer is not installed, we insert a hidden, zero height view as the footer. The setter is unchanged, so our view controller can replace the placeholder with a custom footer at any time. This gives us a dependable reference for the table’s proper content height under any circumstances. If we need the placeholder, it’s only created once, and not until the first -layoutSubviews message is received. This gives the calling code a chance to set a custom footer before the placeholder is created unnecessarily.
ShadowedTables/Classes/PRPShadowedTableView.m
- (UIView *)tableFooterView {
UIView *footer = [super tableFooterView];
if (footer == nil) {
if (self.placeholderFooter == nil) {
CGRect footerFrame = self.frame;
footerFrame.size.height = 0;
placeholderFooter = [[UIView alloc] initWithFrame:footerFrame];
}
self.placeholderFooter.hidden = YES;
footer = self.tableFooterView = self.placeholderFooter;
}
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(16055)
The Mikado Method by Ola Ellnestam Daniel Brolund(13332)
Hello! Python by Anthony Briggs(13139)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(12305)
Dependency Injection in .NET by Mark Seemann(12163)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(10922)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(10763)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10539)
Grails in Action by Glen Smith Peter Ledbrook(10230)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(10153)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(9531)
Hit Refresh by Satya Nadella(9040)
Kotlin in Action by Dmitry Jemerov(8880)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(8670)
The Kubernetes Operator Framework Book by Michael Dame(8488)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8308)
Robo-Advisor with Python by Aki Ranin(8261)
Practical Computer Architecture with Python and ARM by Alan Clements(8234)
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(8202)